package com.person.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.person.model.entity.AgentInfo;
import com.person.model.entity.Result;
import com.person.service.AgentInfoService;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author hhf
 * @Date 2025/3/12
 * @Description
 */
@RestController
@RequestMapping("/agent_info")
public class AgentInfoController {

    @Resource
    private AgentInfoService agentInfoService;

    /**
     * 根据 id 查询 agent_info
     * @param name
     * @return
     */
    @GetMapping("/getByName/{name}")
    public Result getByName(@PathVariable String name) {
        QueryWrapper<AgentInfo> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(name),"name",name);
        return Result.success(agentInfoService.getOne(wrapper));
    }


    /**
     * 根据 id 查询 agent_info
     * @param id
     * @return
     */
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Integer id) {
        return Result.success(agentInfoService.getById(id));
    }


    /**
     * 根据 name 查询 agent_info
     *
     * @param name
     * @return
     */
    @GetMapping("/get_list")
    public Result getAgentInfoListByName(String name) {
        QueryWrapper<AgentInfo> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(name),"name",name);
        List<AgentInfo> list = agentInfoService.list(wrapper);
        return Result.success(list);
    }

}
